package ui.panel.setup.subsidiary;

import cerebrum.entity.FontCacheEntity;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.stage.Stage;
import ui.factory.SingletonFactory;

import java.io.IOException;

public class SetUpMenu extends Application {

    private static SetUpMenu instance;
    private int num = 0;

    //调用单例工厂
    public static SetUpMenu getInstance() {
        if (instance == null) {
            instance = SingletonFactory.getWeakInstace(SetUpMenu.class);
        }
        return instance;
    }


    @Override
    public void start(Stage primaryStage) {
        Pane pane = frequencyMenu(5, 30);
        Scene scene = new Scene(pane, 800, 600);
//        scene.setFill(Color.TRANSPARENT);
        primaryStage.setScene(scene);
//        primaryStage.initStyle(StageStyle.TRANSPARENT);
        primaryStage.show();
    }

    private void getNum(int minSize, int maxSize) {
        if (num <= minSize) {
            num = minSize;

        }
        if (num >= maxSize) {
            num = maxSize;
        }
    }


    public Pane frequencyMenu(int minSize, int maxSize) {
        Pane pane = new Pane();
//        pane.setStyle("-fx-background-color: TRANSPARENT");
        pane.setOpacity(0.8);

        Pane pane1 = new Pane();
        pane1.setPrefWidth(275);
        pane1.setPrefHeight(80);
        pane1.setLayoutX(100);
        pane1.setLayoutY(100);
        pane1.setStyle("-fx-background-color: #f07c82");
        pane1.setBorder(new Border(new BorderStroke(Color.rgb(238, 162, 164), BorderStrokeStyle.SOLID, null, new BorderWidths(10))));


        Label lbl = new Label();
        lbl.setText(String.valueOf(minSize));

        lbl.setLayoutX(123);
        lbl.setLayoutY(13);
        try {
            lbl.setFont(Font.loadFont(FontCacheEntity.class.getResource("/fxml/font/FZYongKTJF_Da.TTF").openStream(), 50));
        } catch (IOException e) {
            e.printStackTrace();
        }


        Button button = new Button();
        button.setStyle("-fx-shape: 'M512 6.144c-279.552 0-506.88 227.328-506.88 506.88s227.328 506.88 506.88 506.88 506.88-227.328 506.88-506.88-227.328-506.88-506.88-506.88z m0 923.136c-229.888 0-416.256-186.88-416.256-416.256 0-229.888 186.88-416.256 416.256-416.256 229.888 0 416.256 186.88 416.256 416.256s-186.88 416.256-416.256 416.256z M743.424 462.336H280.576c-28.16 0-50.688 22.528-50.688 50.688 0 27.648 22.528 50.688 50.688 50.688h462.848c28.16 0 50.688-22.528 50.688-50.688s-22.528-50.688-50.688-50.688z';");
        button.setPrefHeight(40);
        button.setPrefWidth(40);
        button.setLayoutX(30);
        button.setLayoutY(12);
        button.setPadding(new Insets(20));
        button.setOnMouseClicked(e -> {
            num--;
            getNum(minSize, maxSize);
            if (num > 9) {
                lbl.setLayoutX(103);
            }
            lbl.setText(String.valueOf(num));
        });

        Button button2 = new Button();
        button2.setStyle("-fx-shape: 'M511.448 66.205c-245.315 0-444.905 199.59-444.905 444.906 0 245.318 199.59 444.907 444.906 444.907 245.318 0 444.907-199.59 444.907-444.907 0-245.316-199.59-444.906-444.908-444.906z m0 834.198c-214.659 0-389.292-174.63-389.292-389.292 0-214.66 174.633-389.293 389.292-389.293 214.66 0 389.294 174.633 389.294 389.293 0 214.661-174.634 389.292-389.294 389.292z m166.84-417.099H539.257V344.271c0-15.37-12.438-27.806-27.808-27.806s-27.807 12.438-27.807 27.806v139.033H344.611c-15.372 0-27.808 12.438-27.808 27.807 0 15.342 12.437 27.806 27.808 27.806h139.03V677.95c0 15.342 12.438 27.806 27.807 27.806 15.371 0 27.808-12.464 27.808-27.806V538.917h139.031c15.372 0 27.808-12.464 27.808-27.806 0.001-15.37-12.435-27.807-27.807-27.807z'");
        button2.setPrefHeight(40);
        button2.setPrefWidth(40);
        button2.setPadding(new Insets(20));
        button2.setLayoutX(200);
        button2.setLayoutY(12);
        button2.setOnMouseClicked(e -> {
            num++;
            getNum(minSize, maxSize);
            if (num > 9) {
                lbl.setLayoutX(103);
            }
            lbl.setText(String.valueOf(num));
        });

        pane1.getChildren().addAll(button, lbl, button2);
        pane.getChildren().add(pane1);
        return pane;
    }

    public static void main(String[] args) {
        launch(args);
    }

}
